import type { AxiosResponse } from 'axios';
import { apiClient } from '@/services/api';

// 获取项目模板列表
export function getTemplateList(): Promise<AxiosResponse<any>> {
    return apiClient.get('/draft/list');
}
// 新建草稿
export function createTemplate(data: any): Promise<AxiosResponse<any>> {
    return apiClient.post('/draft/add/', data);
}

//删除草稿
export function deleteTemplate(draft_id: string): Promise<AxiosResponse<any>> {
    return apiClient.delete(`draft/delete/${draft_id}/`);
}

//获取公开草稿列表
export function getOpenDraftList(): Promise<AxiosResponse<any>> {
    return apiClient.get('draft/list-public-with-jianyingjson/');
}

//根据草稿id获取单个草稿信息
export function getTemplateById(draft_id: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`draft/detail-with-urls/${draft_id}/`);
}

//上传视频文件
export function uploadVideoFile(data: FormData): Promise<AxiosResponse<any>> {
    return apiClient.post('files/upload/', data, {
        headers: {
            'Content-Type': 'multipart/form-data',
        },
    });
}
//为轨道创建片段
export function createSegment(draft_id: string, track_id: string, data: any): Promise<AxiosResponse<any>> {
    return apiClient.post(`drafts/${draft_id}/tracks/${track_id}/segments/`, data);
}

//更新轨道片段
export function updateSegment(draft_id: string, track_id: string, segment_id: string, data: any): Promise<AxiosResponse<any>> {
    return apiClient.put(`drafts/${draft_id}/tracks/${track_id}/segments/${segment_id}/update/`, data);
}
//删除轨道片段
export function deleteSegment(draft_id: string, track_id: string, segment_id: string): Promise<AxiosResponse<any>> {
    return apiClient.delete(`drafts/${draft_id}/tracks/${track_id}/segments/${segment_id}/`);
}

//批量更新轨道片段
export function updateSegments(draft_id: string, track_id: string, data: any): Promise<AxiosResponse<any>> {
    return apiClient.post(`drafts/${draft_id}/tracks/${track_id}/segments/batch/`, data);
}

//获取操作类型
export function getOperationTypes(operation_type: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`video-operations/types/${operation_type}/`);
}

//更新轨道片段视频操作
export function updateSegmentVideoOperations(draft_id: string, track_id: string, segment_id: string, data: any): Promise<AxiosResponse<any>> {
    return apiClient.post(`drafts/${draft_id}/tracks/${track_id}/segments/${segment_id}/video-operations/`, data);
}

//视频合成
export function composeVideo(draft_id: string): Promise<AxiosResponse<any>> {
    return apiClient.post(`draft/export/${draft_id}/`);
}

//获取片段操作列表
export function getSegmentOperations(draft_id: string, track_id: string, segment_id: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`drafts/${draft_id}/tracks/${track_id}/segments/${segment_id}/operations/`);
}

// 旧版本
// 更新草稿
// draft_id: 草稿的唯一标识
// data: 更新的草稿数据
export function updateTemplate(draft_id: string, data: any): Promise<AxiosResponse<any>> {
    return apiClient.put(`/draft/update/${draft_id}/`, data);
}

// 获取对应草稿的所有轨道信息
export function getTrackList(draft_id: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`track/${draft_id}/list`);
}

//获取草稿全部数据
export function getDraftCompleteData(draft_id: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`draft/complete-data/?draft_id=${draft_id}`);
}

//添加文字的配置信息
export function addTextConfig(data: any): Promise<AxiosResponse<any>> {
    return apiClient.post(`text/config/add/`, data);
}

//添加文字轨道项
export function addTextTrackItem(data: any): Promise<AxiosResponse<any>> {
    return apiClient.post(`text/item/add/`, data);
}
// 获取文字配置素材
// 修改为使用 item_id 参数的新接口
// 请求示例: /api/text/material-config/?item_id=text-123456789012
export function getTextMaterialConfig(item_id: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`text/material-config/?item_id=${item_id}`);
}

//删除文字轨道项
export function deleteTextTrackItem(item_id: string): Promise<AxiosResponse<any>> {
    return apiClient.delete(`text/delete/?item_id=${item_id}`);
}

//获取单个草稿的视频素材列表
export function getVideoMaterialList(draft_id: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`video/material/list/?draftId=${draft_id}`);
}

//获取单个草稿的文字素材列表
export function getTextMaterialList(draft_id: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`text/materials-by-draft/?draftId=${draft_id}`);
}
//获取单个草稿的音频素材列表
export function getAudioMaterialList(draft_id: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`audio/material/list/?draftId=${draft_id}`);
}

// // 修改项目模板
// export function updateTemplate(
//     pk: number,
//     data: any,
// ): Promise<AxiosResponse<any>> {
//     return apiClient.put(`/template/${pk}/`, data);
// }

// 删除项目模板
// export function deleteTemplate(pk: number): Promise<AxiosResponse<any>> {
//     return apiClient.delete(`/template/${pk}/delete/`);
// }

// 获取文本的动画列表
export function getAnimationList(): Promise<AxiosResponse<any>> {
    return apiClient.get('/text/categories/');
}
// 获取免费字体列表
export function getFreeFonts(): Promise<AxiosResponse<any>> {
    return apiClient.get('/fonts/free/');
}

// 获取视频intro动画列表
export function getVideoIntroAnimations(): Promise<AxiosResponse<any>> {
    return apiClient.get('/video/animations/intro/');
}

// 获取视频outro动画列表
export function getVideoOutroAnimations(): Promise<AxiosResponse<any>> {
    return apiClient.get('/video/animations/outro/');
}

// 获取视频group动画列表
export function getVideoGroupAnimations(): Promise<AxiosResponse<any>> {
    return apiClient.get('/video/animations/group/');
}

// 获取音色效果列表
export function getToneEffects(): Promise<AxiosResponse<any>> {
    return apiClient.get('/audio/effects/tone/');
}

// 获取场景音效果列表
export function getAudioSceneEffects(): Promise<AxiosResponse<any>> {
    return apiClient.get('/audio/effects/scene/');
}

// 获取声音成曲效果列表
export function getSpeechToSongEffects(): Promise<AxiosResponse<any>> {
    return apiClient.get('/audio/effects/song/');
}

// 获取所有音频效果列表
export function getAllAudioEffects(): Promise<AxiosResponse<any>> {
    return apiClient.get('/audio/effects/all/');
}

// 获取所有滤镜列表
export function getAllFilters(): Promise<AxiosResponse<any>> {
    return apiClient.get('/video/filters/all/');
}

// 获取所有转场效果列表
export function getAllTransitions(): Promise<AxiosResponse<any>> {
    return apiClient.get('/video/transitions/all/');
}

// // 获取转场效果分类,没配置url
// export function getTransitionCategories(): Promise<AxiosResponse<any>> {
//     return apiClient.get("/video/transitions/categories/");
// }

// 获取所有视频特效列表
export function getAllVideoEffects(): Promise<AxiosResponse<any>> {
    return apiClient.get('/video/effects/all/');
}

// 获取视频特效分类
export function getVideoEffectCategories(): Promise<AxiosResponse<any>> {
    return apiClient.get('/video/effects/categories/');
}

//添加视频配置
export function addVideoConfig(data: any): Promise<AxiosResponse<any>> {
    return apiClient.post(`video/config/add/`, data);
}

//添加视频轨道项
export function addVideoTrackItem(data: any): Promise<AxiosResponse<any>> {
    return apiClient.post(`video/item/add/`, data);
}

//删除视频轨道项
export function deleteVideoTrackItem(item_id: string): Promise<AxiosResponse<any>> {
    return apiClient.delete(`video/item/delete/${item_id}/`);
}

//添加音频配置
export function addAudioConfig(data: any): Promise<AxiosResponse<any>> {
    return apiClient.post(`audio/config/add/`, data);
}

//添加音频轨道项
export function addAudioTrackItem(data: any): Promise<AxiosResponse<any>> {
    return apiClient.post(`audio/item/add/`, data);
}

//删除音频轨道项
export function deleteAudioTrackItem(item_id: string): Promise<AxiosResponse<any>> {
    return apiClient.delete(`audio/item/delete/${item_id}/`);
}

//修改音频配置
export function updateAudioConfig(data: any): Promise<AxiosResponse<any>> {
    return apiClient.put(`audio/config/update/`, data);
}
//修改文字配置
export function updateTextConfig(data: any): Promise<AxiosResponse<any>> {
    return apiClient.put(`text/config/update/`, data);
}

//修改视频配置
export function updateVideoConfig(data: any): Promise<AxiosResponse<any>> {
    return apiClient.put(`video/config/update/`, data);
}

//保存剪映json文件
export function saveProjectJson(data: any): Promise<AxiosResponse<any>> {
    return apiClient.post(`draft/generate_cutdraft/`, data);
}

//给根据id获取音频素材配置
export function getAudioConfigById(item_id: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`audio/material-config/?item_id=${item_id}`);
}
//根据id获取文字素材配置
export function getTextConfigById(item_id: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`text/material-config/?item_id=${item_id}`);
}
//根据id获取视频素材配置
export function getVideoConfigById(item_id: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`video/material-config/?item_id=${item_id}`);
}

//根据轨道id删除轨道
export function deleteTrack(trackId: string, draft_id: string): Promise<AxiosResponse<any>> {
    return apiClient.delete(`track/delete/${trackId}?draftId=${draft_id}`);
}

//添加贴纸轨道项
export function addStickerTrackItem(data: any): Promise<AxiosResponse<any>> {
    return apiClient.post(`sticker/item/add/`, data);
}

//根据id获取贴纸配置信息
export function getStickerConfigById(item_id: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`sticker/material-config/?item_id=${item_id}`);
}

//获取对应草稿贴纸列表
export function getStickerMaterialList(draft_id: string): Promise<AxiosResponse<any>> {
    return apiClient.get(`sticker/material/list/?draftId=${draft_id}`);
}

//删除对应贴纸项
export function deleteStickerItem(item_id: string): Promise<AxiosResponse<any>> {
    return apiClient.delete(`sticker/item/delete/${item_id}/`);
}

//更新贴纸配置信息
export function updateStickerConfig(data: any): Promise<AxiosResponse<any>> {
    return apiClient.put(`sticker/config/update/`, data);
}

//保存完整草稿自定义json
export function saveCompleteDraftJson(draft_id: string): Promise<AxiosResponse<any>> {
    return apiClient.post(`draft/update-complete-json/?draft_id=${draft_id}`);
}

//下载草稿素材包zip
export function downloadDraftMaterialZip(draft_id: string): Promise<AxiosResponse<any>> {
    return apiClient.post(`draft/download-files/?draft_id=${draft_id}`, {}, { responseType: 'blob' });
}

//下载剪映json文件
export function downloadJianyingJson(draft_id: string): Promise<AxiosResponse<any>> {
    return apiClient.post(`draft/download-jianying-json/?draft_id=${draft_id}`, {}, { responseType: 'blob' });
}

//通过音频文字新建文字轨道项
export function addTextTrackItemByAudioText(data: any): Promise<AxiosResponse<any>> {
    return apiClient.post(`text/auto-break-text/`, data);
}
